package com.ccys.cms.controller.formulation;


import com.ccys.cms.service.formulation.RouteDoctorService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.web.formulation.RouteDoctorDto;
import com.ccys.db.dto.web.productAndService.NumEnum;
import com.ccys.db.entity.TblFormulationRouteDoctor;
import com.ccys.db.mapper.TblFormulationRouteDoctorMapper;
import com.ccys.db.vo.web.formulation.RouteDoctorVo;
import com.ccys.db.vo.web.productAndService.IdNameVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/formulation")
@Api(tags = "routedoctor管理")
public class RouteDoctorController {


    @Resource
    private RouteDoctorService routeDoctorService;

    @Resource
    private TblFormulationRouteDoctorMapper mapper;


    @PostMapping("routeDoctor")
    @ApiOperation("新增")
    @Transactional
    public ResponseResult insert(TblFormulationRouteDoctor model) {

        int i = routeDoctorService.insertOrUpdate(model);
        return ResponseResult.update(i);
    }


    @PutMapping("routeDoctor")
    @ApiOperation("修改")
    @Transactional
    public ResponseResult update(TblFormulationRouteDoctor model) {

        int i = routeDoctorService.insertOrUpdate(model);
        return ResponseResult.update(i);
    }




    @DeleteMapping("routeDoctor")
    @ApiOperation("根据id删除")
    @Transactional
    public ResponseResult delete(String id) {

        TblFormulationRouteDoctor model = new TblFormulationRouteDoctor();
        model.setId(id);
        model.setDelFlag(NumEnum.DEL.getCode());
        return ResponseResult.update(routeDoctorService.updateEntityById(model));
    }


    @GetMapping("routeDoctor")
    @ApiOperation(value = "分页查询", notes = "排序字段  t1.name(指的route(Doc)列) / t3.name / t1.disp_order / t1.status / t2.user_fullname / t1.created_on")
    public ResponseResult<PageInfo<RouteDoctorVo>, Object> getPage(RouteDoctorDto dto) {


        return routeDoctorService.getPage(dto);
    }

    @GetMapping("routeDoctor/list")
    @ApiOperation(value = "根据formulation的id获取routedoctor集合")
    public ResponseResult<List<IdNameVo>, Object> getList(String formulationId) {

        List<IdNameVo> list = mapper.getRouteDoctorList(formulationId);

        return ResponseResult.success(list);
    }

}
